﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Main_Video : System.Web.UI.Page
{
    EncriptManager em = new EncriptManager();
    VideoDao vd = new VideoDao();
    DataTable dt = null;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            dt = vd.getVideo("0");
            dlvideo.DataSource = dt;
            dlvideo.DataBind();
            if (dt != null)
            {
                for (int i = 0; i < dlvideo.Items.Count; i++)
                {
                    HyperLink hlvideo = dlvideo.Items[i].FindControl("hlvideo") as HyperLink;
                    Label labVname = dlvideo.Items[i].FindControl("labVname") as Label;
                    string vid = em.Encript(dt.Rows[i][0].ToString());
                    hlvideo.NavigateUrl = "VideoInfo.aspx?vid=" + vid;
                    if (labVname.Text.Length > 9)
                    {
                        labVname.Text = labVname.Text.Substring(0, 9) + "...";
                    }
                }
            }
        }
    }
    protected void btnsearch_Click(object sender, EventArgs e)
    {
        dt = vd.getVideo(txtname.Text,ddltype.SelectedValue);
        if (dt == null)
        {
            string script = "<script>window.alert('对不起，没有相关视频信息！');</script>";
            Page.RegisterClientScriptBlock("", script);
            return;
        }
        if (dt.Rows.Count == 0)
        {
            string script = "<script>window.alert('对不起，没有相关视频信息！');</script>";
            Page.RegisterClientScriptBlock("", script);
            return;
        }
        dlvideo.DataSource = dt;
        dlvideo.DataBind();
        if (dt != null)
        {
            for (int i = 0; i < dlvideo.Items.Count; i++)
            {
                HyperLink hlvideo = dlvideo.Items[i].FindControl("hlvideo") as HyperLink;
                Label labVname = dlvideo.Items[i].FindControl("labVname") as Label;
                string vid = em.Encript(dt.Rows[i][0].ToString());
                hlvideo.NavigateUrl = "VideoInfo.aspx?vid=" + vid;
                if (labVname.Text.Length > 9)
                {
                    labVname.Text = labVname.Text.Substring(0, 9) + "...";
                }
            }
        }
    }
}
